package com.haike.pushjobs.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;


public class BaseController {

    protected final Logger logger = LoggerFactory.getLogger(BaseController.class);


    //region 返回数据

    /**
     * 返回成功消息
     *
     * @param data
     * @param message
     * @return
     */
    public Map<String, Object> success(Object data, String message) {
        Map<String, Object> map = new HashMap<String, Object>() {
            {
                put("code", 200);
                put("data", data);
                put("msg", message);
                put("tm", new Date());
            }
        };
        return map;
    }

    /**
     * 返回成功消息
     *
     * @param data
     * @return
     */
    public Map<String, Object> success(Object data) {
        return success(data, "");
    }

    /**
     * 返回成功消息
     *
     * @param
     * @return
     */
    public Map<String, Object> success() {
        return success(null, "");
    }


    /**
     * 返回失败消息
     *
     * @param message
     * @return
     */
    public Map<String, Object> error(String message) {
        Map<String, Object> map = new HashMap<String, Object>() {
            {
                put("code", 500);
                put("msg", message);
                put("tm", new Date());
            }
        };
        return map;
    }


}
